/*
 * Copyright (c) 2023-2023 elsfs Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.elsfs.cloud.permission.api.entity;

import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.annotation.write.style.ColumnWidth;
import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.Comparator;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.elsfs.cloud.api.validation.group.GroupValidation;
import org.elsfs.cloud.common.annotations.Spell;
import org.elsfs.cloud.common.core.entity.BaseTreeEntity;

/**
 * 菜单
 *
 * @author zeng
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ColumnWidth(20)
public class SysMenu extends BaseTreeEntity<SysMenu, String> {

  @TableId
  @Schema(description = "菜单")
  @NotBlank(
      message = "菜单不能为空",
      groups = {GroupValidation.Edit.class})
  private String menuId;

  /** 菜单名称 */
  @Schema(description = "菜单名称")
  @TableField(condition = SqlCondition.LIKE)
  @Spell
  @ExcelProperty(value = "菜单名称")
  @NotBlank(
      message = "菜单名称不能为空",
      groups = {GroupValidation.Add.class, GroupValidation.Edit.class})
  private String menuName;

  /** 路由地址 */
  @Schema(description = "路由地址")
  @ExcelProperty(value = "路由地址")
  private String routePath;

  /** 上级菜单 */
  @Schema(description = "上级菜单")
  @ExcelProperty(value = "上级菜单")
  @NotBlank(
      message = "上级菜单不能为空",
      groups = {GroupValidation.Add.class, GroupValidation.Edit.class})
  private String parentId;

  @Schema(description = "图标")
  @ExcelProperty(value = "图标")
  private String icon;

  @Schema(description = "组件")
  @ExcelProperty(value = "组件")
  private String component;

  /** 是否显示 */
  @Schema(description = "是否显示")
  @ExcelProperty(value = "是否显示")
  private Boolean isShow;

  /** 排序值，越小越靠前 */
  @Schema(description = "排序值")
  @ExcelProperty(value = "排序值")
  @NotNull(
      message = "排序值不能为空",
      groups = {GroupValidation.Add.class, GroupValidation.Edit.class})
  private Integer orderNo;

  /** 是否缓存路由，0否，1是 */
  @Schema(description = "是否缓存路由")
  @ExcelProperty(value = "是否缓存路由")
  private Boolean keepAlive;

  /** 是否外链 */
  @Schema(description = "是否外链")
  @ExcelProperty(value = "是否外链")
  private Boolean isExt;

  /** 菜单类型，0目录，1菜单，2按钮 */
  @Schema(description = "菜单类型")
  @ExcelProperty(value = "菜单类型")
  @NotNull(
      message = "菜单类型不能为空",
      groups = {GroupValidation.Add.class, GroupValidation.Edit.class})
  private String type;

  /** 状态 */
  @Schema(description = "状态")
  @ExcelProperty(value = "状态")
  private String status;

  @Override
  public String getId() {
    return menuId;
  }

  @Override
  public int compareTo(SysMenu o) {
    if (null == o) {
      return 1;
    }
    return Comparator.comparing(SysMenu::getOrderNo).compare(this, o);
  }
}
